﻿using System;
using System.Diagnostics;
using EnvDTE;
using EnvDTE80;

namespace Specialwork.AddIns.VisualStudio
{
    /// <summary>
    /// 
    /// </summary>
    public static class OutputWindows
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outputWindowPane"></param>
        public static void ActivateOutputPane(OutputWindowPane outputWindowPane)
        {
            if (outputWindowPane == null) throw new ArgumentNullException();

            outputWindowPane.Activate();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outputWindowPane"></param>
        public static void ClaerOutputPane(OutputWindowPane outputWindowPane)
        {
            if (outputWindowPane == null) throw new ArgumentNullException();

            outputWindowPane.Clear();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="application"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public static OutputWindowPane CreateOutputPane(DTE2 application, string category)
        {
            if (application == null) throw new ArgumentNullException();
            if (string.IsNullOrEmpty(category)) throw new ArgumentNullException();

            Window2 window = application.Windows.Item(Constants.vsWindowKindOutput) as Window2;
            OutputWindow outputWindow = window.Object as OutputWindow;
            OutputWindowPanes outputWindowPanes = outputWindow.OutputWindowPanes;
            OutputWindowPane result = outputWindowPanes.Add(category);

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="outputWindowPane"></param>
        /// <param name="message"></param>
        public static void WriteLine(OutputWindowPane outputWindowPane, string message)
        {
            try
            {
                if (outputWindowPane == null) throw new ArgumentNullException();

                outputWindowPane.OutputString(message + Environment.NewLine);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
        }
    }
}